package org.example.route.controller.AdminController;




import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.route.model.dto.BaseRequest;
import org.example.route.model.dto.ProvinceDTO;
import org.example.route.model.dto.ProvinceQueryDTO;
import org.example.route.model.pojo.Result;
import org.example.route.model.vo.ProvinceVO;
import org.example.route.service.ProvinceService;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/province")
@Slf4j
@Tag(name = "省份管理")
public class ProvinceController {
    @Autowired
    private ProvinceService provinceService;
    //获得所有省份的方法


    @Cacheable(cacheNames = "provinceCache",key = "T(java.util.Objects).hash(#provinceQueryDTO.name)")
    @Operation(summary = "查询省份列表")
    @PostMapping("/list")
    public Result<List<ProvinceVO>> list(@RequestBody ProvinceQueryDTO provinceQueryDTO)
    {
        log.info("查询省份列表，{}", provinceQueryDTO);
        List<ProvinceVO> provinceVOS = provinceService.list(provinceQueryDTO);
        return Result.success(provinceVOS);
    }


    @CacheEvict(cacheNames = "provinceCache",allEntries = true)
    @Operation(summary = "添加省份")
    @PostMapping("/add")
    public Result add(@RequestBody ProvinceDTO provinceDTO)
    {
        log.info("添加省份,{}", provinceDTO);
        provinceService.add(provinceDTO);
        return Result.success();
    }

    @CacheEvict(cacheNames = "provinceCache",allEntries = true)
    @Operation(summary = "删除省份")
    @PostMapping("/delete")
    public Result delete(@RequestBody BaseRequest baseRequest)
    {
        log.info("删除省份,{}", baseRequest);
        provinceService.delete(baseRequest);
        return Result.success();
    }


}
